/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Tools;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author basisc20ma
 */
public class Koneksi {

    public static Connection open(String url, String userId, String password) {
        Connection conn = null;
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(url);

            conn = ds.getConnection(userId, password);
            System.out.println("Koneksi OK");


        } catch (SQLException ex) {
            Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
        }
        return conn;
    }

    public static Connection bukaKoneksi() {
        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        String userId = "hr";
        String password = "115314023";

//        String url = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
//        String userId = "mhs115314095";
//        String password = "mhs115314095";
        
        Connection conn = null;
        try {


            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(url);

            conn = ds.getConnection(userId, password);
            System.out.println("Koneksi OK");


        } catch (SQLException ex) {
            Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
        }
        return conn;
    }
    
//    public static Connection KoneksiLogin2 (String uname, String pass, String url){
//        Connection conn = null;
//        try {
//            OracleDataSource ds;
//            ds = new OracleDataSource();
//            ds.setURL(url);
//
//            conn = ds.getConnection(uname, pass);
//            JOptionPane.showMessageDialog(null,"Selamat Datang Anda Telah Berhasil Login");
//            MenuUtama menu = new MenuUtama();
//            menu.setVisible(true);
//
//        } catch (SQLException ex) {
//            JOptionPane.showMessageDialog(null,"Sorry Anda Gagal Login");
//            LoginForm lg = new LoginForm();
//            lg.setVisible(true);
//        }
//        return conn;
//    }
    
    
//    public static Connection KoneksiLogin (String uname, String pass, String url){
////        Login lg = new Login();
////        lg.setUserName(uname);
////        lg.setPassword(pass);
////        lg.setNamaUrl(url);
//        
//        Connection conn = null;
//        try {
//            OracleDataSource ds;
//            ds = new OracleDataSource();
//            ds.setURL(url);
//
//            conn = ds.getConnection(uname, pass);
//            JOptionPane.showMessageDialog(null,"Selamat Datang Anda Telah Berhasil Login");
//
//
//        } catch (SQLException ex) {
//            Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        return conn;        
//    }
}
